package org.gianrishandy.IEEE;

public class Convert {
	
	public static String intToBinary(int in){
		String binary = Integer.toBinaryString(in);
		
		if(binary.length()<8){
			binary = "0" + binary;
		}
		
		return binary;
	}
	
	public static int binaryToInt(String binary){
		int r = 0;
		int it = 1;
		
		for(int i=binary.length();i>=1;i--){
			String bin = String.valueOf(binary.charAt(i-1));
			
			if(bin.equalsIgnoreCase("1")){
				r = r + (it * Integer.parseInt(bin));
			}
			
			it = it * 2;
		}
		
		return r;
	}
}
